package com.he.cmsservice.controller;


import com.he.cmsservice.entity.CrmBanner;
import com.he.cmsservice.service.CrmBannerService;
import com.he.commonutils.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author testhejinyu
 * @since 2021-06-10
 */
@RestController
@Api(description = "后台轮播图管理")
@RequestMapping("/cmsservice/crm-banner")
@CrossOrigin
public class CrmBannerController {

    @Autowired
    private CrmBannerService bannerService;

    @PostMapping("/addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){
        bannerService.addBanner(crmBanner);
        return R.ok();
    }

    @DeleteMapping("/deleteBanner/{id}")
    public R deleteBanner(
            @PathVariable("id") String id
    ){
        bannerService.deleteBanner(id);
        return R.ok();
    }

    @GetMapping("/getBannerById/{id}")
    public R getBannerById(
            @PathVariable("id") String id
    ){
        CrmBanner crmBanner = bannerService.getBannerById(id);
        return R.ok().data("crmBanner",crmBanner);
    }

    @PostMapping("/updateBanner")
    public R updateBanner(
            @RequestBody CrmBanner crmBanner
    ) {
        bannerService.updateBanner(crmBanner);
        return R.ok();
    }

    @GetMapping("/findAllBanner")
    public R findAllBanner(){
        List<CrmBanner> result = bannerService.findAllBanner();
        return R.ok().data("bannerList", result);
    }

}

